package com.jwyming.secKilling;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * Created by user on 2017/4/3.
 */
public class Test {
    static Logger logger = Logger.getLogger(Test.class.getName());

    public static void main(String[] args) throws Exception {
        Test test = new Test();
//        test.testSeleceOptions();
//        test.testHashMap();
        test.testConfigInfo();
    }

    public void testSeleceOptions() {
        String demo = "<select name='list'><option value='3'>First value</option><option value='4'>Second value</option><option value='5'>Third value</option></select>";
        Document document = Jsoup.parse(demo);
//        Elements options = document.select("select > option");
        Elements selectElements = document.getElementsByTag("select");

        for (Element selectElement : selectElements) {
            String key = selectElement.attr("name");
            Elements options = selectElement.select("option");
            List<String> values = new ArrayList<String>();
            for (Element element : options) {
                values.add(element.attr("value"));
            }
            logger.info("select name=" + key + ", values=" + values);
            logger.info("first value=" + values.get(0));
            logger.info("last value=" + values.get(values.size() - 1));
        }
    }

    public void testHashMap() {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("form", "1");
        hashMap.put("form", "2");

        logger.info((String) hashMap.get("form"));
    }

    public void testConfigInfo() throws Exception {
        ConfigInfo configInfo = new ConfigInfo();
        List<ConfigItem> configItems = configInfo.getConfigItems();
        for(ConfigItem configItem : configItems) {
            logger.info(configItem.getProperty("product.params"));
        }
    }
}
